<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <style>
    * {
      margin: 0;
      padding: 0;
      box-sizing: border-box;
    }

    div {
      width: 50%;
      aspect-ratio: 3/1;
    }

    body {
      width: 100%;
      height: 100vh;
      overflow: hidden;
      display: flex;
      justify-content: center;
      align-items: center;
    }

    #canvas {
      width: 300px;
      height: 300px;
      border: 1px solid #000;
      background-color: red;
    }
  </style>
  <canvas id='canvas'></canvas>
  <script>
    const canvasDom = document.getElementById('canvas');
    function init() {
      canvasDom.width = canvasDom.clientWidth * devicePixelRatio
      canvasDom.height = canvasDom.clientHeight * devicePixelRatio
    }
    init()


    // @ts-ignore


    function calculatePoints(x, y, distance) {
      // 计算四个角的坐标
      const topLeft = [x - distance, y - distance];
      const topRight = [x + distance, y - distance];
      const bottomLeft = [x - distance, y + distance];
      const bottomRight = [x + distance, y + distance];

      // 计算四条边的中点坐标
      const topCenter = [x, y - distance];
      const bottomCenter = [x, y + distance];
      const leftCenter = [x - distance, y];
      const rightCenter = [x + distance, y];

      const center = [x, y];

      // 返回所有 8 个点的坐标
      return {
        center,
        topLeft,
        topRight,
        bottomLeft,
        bottomRight,
        topCenter,
        bottomCenter,
        leftCenter,
        rightCenter
      }

    }

  </script>
</body>

</html>